#include "Tracer.h"
#include "STPPacker.h"
using namespace libemb;

void TestSTPPacker()
{
    std::string inputStr;
	while(1)
	{
		TRACE_YELLOW("q ---> quit.\n");
		TRACE_YELLOW("1 ---> unpack test.\n");
		TRACE_YELLOW("2 ---> pack test.\n");
		std::cin >> inputStr;
        std::cout << inputStr<<std::endl;
		if("q"==inputStr) 
		{
			return;
		}
		else if("1"==inputStr)
		{
            std::string stp01("1111\xFE\xFE\xFE\xFE""2222\xFE",13);
            std::string stp02("\xFE\x00\x0c",3);
            std::string stp03("abcd\xFE\xFE\xFE\xFE\xFE\xFE\x00\x0c""ef\xFE\xFE\xFE\xFE\x0a\x0a",20);
            std::string stp04("\xFE\xFE\xFE",3);
            TRACE_HEX("stp01",stp01.c_str(),stp01.size());
            TRACE_HEX("stp02",stp02.c_str(),stp02.size());
            TRACE_HEX("stp03",stp03.c_str(),stp03.size());
            TRACE_HEX("stp04",stp04.c_str(),stp04.size());
            STPPacker packer;
            packer.unpackOn(stp01.c_str(),stp01.size());
            packer.unpackOn(stp02.c_str(),stp02.size());
            packer.unpackOn(stp03.c_str(),stp03.size());
            packer.unpackOn(stp04.c_str(),stp04.size());
        }
        else if("2"==inputStr)
		{
            STPPacker packer;
            char* stp1 = "1234567890";
            char* stp2 = "\xFE\xFE""123456\xFE\xFE";

            std::string result1 = packer.packData(stp1,10);
            TRACE_HEX("stp1",result1.c_str(),result1.size());

            std::string result2 = packer.packData(stp2,10);
            TRACE_HEX("stp2",result2.c_str(),result2.size());

            packer.unpackOn(result1.c_str(),result1.size());
            packer.unpackOn(result2.c_str(),result2.size());
        }
        inputStr.clear();
    }
}
